# -*- coding: utf-8 -*- 
# @Time : 2020-12-16 22:14 
# @Author : derek.zhang 
# @File : forms.py 
# @Software: PyCharm
from django.contrib.auth.models import User
from django import forms

from appinput.models import App


class AppForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        initial = kwargs.get('initial', {})
        kwargs['initial'] = initial
        super().__init__(*args, **kwargs)

    name = forms.CharField(
        required=True,
        error_messages={'required': '不能为空'},
        label=u'App组件名称',
        widget=forms.TextInput(
            attrs = {
                'placeholder': "名称",
                'class': 'input-text',
            }
        )
    )

    description = forms.CharField(
        required = False,
        label = u'描述',
        widget =  forms.Textarea(
            attrs = {
                'placeholder': "描述",
                'class':'input-text',
            }
        )
    )

    jenkins_job = forms.CharField(
        required = True,
        error_messages = {'required': '不能为空'},
        label = u'JENKINS JOB 名称',
        widget =  forms.TextInput(
            attrs = {
                'placeholder': "名称",
                'class':'input-text',
            }
        )
    )

    git_url = forms.CharField(
        required = True,
        error_messages = {'required': '不能为空'},
        label = u'GIT 地址',
        widget =  forms.TextInput(
            attrs = {
                'placeholder': "GIT 地址",
                'class':'input-text',
            }
        )
    )

    dir_build_file = forms.CharField(
        required = True,
        error_messages = {'required': '不能为空'},
        label = u'编译目录',
        widget =  forms.TextInput(
            attrs = {
                'placeholder': "./",
                'class':'input-text',
            }
        )
    )

    build_cmd = forms.CharField(
        required = True,
        error_messages = {'required': '不能为空'},
        label = u'编译命令',
        widget =  forms.TextInput(
            attrs = {
                'placeholder': "编译命令",
                'class':'input-text',
            }
        )
    )

    package_name = forms.CharField(
        label = u'软件包名称',
        widget =  forms.TextInput(
            attrs = {
                'placeholder': "编译后的软件包名称，没有可不填",
                'class':'input-text',
            }
        )
    )

    zip_package_name = forms.CharField(
        label = u'压缩包名称',
        widget =  forms.TextInput(
            attrs = {
                'placeholder': "软件包和配置文件集成的压缩包，没有可不填",
                'class':'input-text',
            }
        )
    )

    is_restart_status = forms.CharField(
        required = True,
        error_messages = {'required': '不能为空'},
        label = u'是否重启服务',
        widget =  forms.CheckboxInput(
            attrs = {
                'class':'raido-box',
            }
        )
    )

    manage_user =  forms.ModelChoiceField(
        queryset = User.objects.all(),
        label = u"管理员",
        widget = forms.Select(
            attrs = {
                'style': """width:40%;""",
                'class': 'select-box'
            }
        )
    )

    script_url = forms.CharField(
        label = u'脚本链接',
        widget=forms.TextInput(
            attrs={
                'placeholder':"http://[nginx]/script/[app_name]/[script_name]",
                'class': 'input-text'
            }
        )
    )

    class Meta:
        model = App
        exclude = ['op_log_no']